<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${projectName}</title>
<script type="text/javascript"
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css">
body {
	height: 100%;
}

.fieldTitle {
	width: 100px !important;
}

.mini-tabs-leftButton, .mini-tabs-rightButton {
	display: none;
}

.mini-tabs-scrollCt {
	border-top: 0;
}

.mini-tabs-bodys {
	padding: 0;
}

.headerpan {
	margin-left: 10px;
	font-size: 14px;
	font-weight: bold;
}
#UserPhoto{
	background-image: url('<c:url value="/share/images/test.jpg"></c:url>');
	background-size:150px 210px;
	width:150px;
	height: 210px;
	vertical-align: middle;
	margin-left:auto; 
	margin-right:auto;
}
#explain{
	color: red;
}

</style>
<script type="text/javascript">
	var typeData = [ {
		id : 0,
		text : "",
		note : ""
	}, {
		id : 1,
		text : "持续返费",
		note : "比如：每隔10天返100元，返费10次，则总共返费1000元。"
	}, {
		id : 2,
		text : "叠加返费",
		note : "比如：第1个10天返100元，第二个10天返200元，直到第10个10天返1000元，总返5500元。"
	}, {
		id : 3,
		text : "一次性返费",
		note : "比如：满10天返100元，总计返费就只有100元。"
	}, {
		id : 4,
		text : "按工作日返费",
		note : "比如：每满1天返100元，返费总次数10次，则总共返费1000元。"
	}, {
		id : 5,
		text : "分阶段返费",
		note : "比如：分两个阶段返费，每个阶段按照不同金额持续返费。"
	} ];
</script>
</head>
<body>
	<form id="dataForm">
		<div class="formContent">
			<input id="OrgNo" name="OrgNo" class="mini-hidden"
				style="width: 100%;" />
			<input id="Nature" name="Nature" class="mini-hidden"
				style="width: 100%;" />
			<table class="formContentTable type1" id="type1">
				<tr>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
				</tr>
				<tr>
					<td class="fieldTitle">返费对象</td>
					<td class="fieldContent"><input name="SourceTypeId"
						id="SourceTypeId" required="true" class="mini-combobox"
						style="width: 100%;" textField="SourceType" valueField="Id"
						url="<c:url value='/source/type'></c:url>"
						showNullItem="false" allowInput="false"
						onvaluechanged="" /></td>
					<td class="fieldTitle">预计返费类型</td>
					<td class="fieldContent"><input name="RewardType"
						id="RewardType" required="true" class="mini-combobox"
						style="width: 100%;" textField="RewardType" valueField="TypeNo"
						url="<c:url value='/common/type/reward_type'></c:url>"
						showNullItem="false" allowInput="false"
						onvaluechanged="changeType" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">返费类型说明</td>
					<td class="fieldTitle" colspan="3"><span id="explain"></span></td>
				</tr>
				<tr>
					<td class="fieldTitle">开始日期</td>
					<td class="fieldContent"><input id="StartTime" enabled="true" required="true"
						name="StartTime" class="mini-datepicker" style="width: 100%;" /></td>
					<td class="fieldTitle">结束日期</td>
					<td class="fieldContent"><input id="EndTime" enabled="true" required="true"
						name="EndTime" class="mini-datepicker" style="width: 100%;" /></td>
				</tr>
				<tr class="special">
					<td class="fieldTitle" colspan="4"><b>第一阶段返费：</b></td>
				</tr>
				<tr>
					<td class="fieldTitle">一级返费(元)</td>
					<td class="fieldContent"><input id="Amount1" name="Amount1"
						class="mini-textbox" style="width: 100%;" required="true"
						vtype="float" onvaluechanged="changeAmount" value="0.0" /></td>
					<td class="fieldTitle">二级返费(元)</td>
					<td class="fieldContent"><input id="Amount2" name="Amount2"
						class="mini-textbox" style="width: 100%;" required="false"
						vtype="float" onvaluechanged="changeAmount" value="0.0" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">三级返费(元)</td>
					<td class="fieldContent"><input id="Amount3" name="Amount3"
						class="mini-textbox" style="width: 100%;" required="false"
						vtype="float" onvaluechanged="changeAmount" value="0.0" /></td>
					<td class="fieldTitle">四级返费(元)</td>
					<td class="fieldContent"><input id="Amount4" name="Amount4"
						class="mini-textbox" style="width: 100%;" required="false"
						vtype="float" onvaluechanged="changeAmount" value="0.0" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">要求工作天数</td>
					<td class="fieldContent"><input id="WorkDay" name="WorkDay"
						class="mini-textbox" style="width: 100%;" required="true"
						vtype="int" value="30" /></td>
					<td class="fieldTitle">返费次数</td>
					<td class="fieldContent"><input id="LimitCount1" name="LimitCount1"
						class="mini-textbox" style="width: 75%;" required="true"
						vtype="int" onvaluechanged="changeAmount" value="1" />
						长期<input id="LongReward" name="LongReward"
						class="mini-checkbox" style="width: 45%;" required="true"
						 /></td>
				</tr>
				<tr class="special">
					<td class="fieldTitle" colspan="4"><b>第二阶段返费：</b></td>
				</tr>
				<tr class="special">
					<td class="fieldTitle">一级返费(元)</td>
					<td class="fieldContent"><input id="SubAmount1" name="SubAmount1"
						class="mini-textbox" style="width: 100%;" required="true"
						vtype="float" onvaluechanged="changeAmount" value="0.0" /></td>
					<td class="fieldTitle">二级返费(元)</td>
					<td class="fieldContent"><input id="SubAmount2" name="SubAmount2"
						class="mini-textbox" style="width: 100%;" required="false"
						vtype="float" onvaluechanged="changeAmount" value="0.0" /></td>
				</tr>
				<tr class="special">
					<td class="fieldTitle">三级返费(元)</td>
					<td class="fieldContent"><input id="SubAmount3" name="SubAmount3"
						class="mini-textbox" style="width: 100%;" required="false"
						vtype="float" onvaluechanged="changeAmount" value="0.0" /></td>
					<td class="fieldTitle">四级返费(元)</td>
					<td class="fieldContent"><input id="SubAmount4" name="SubAmount4"
						class="mini-textbox" style="width: 100%;" required="false"
						vtype="float" onvaluechanged="changeAmount" value="0.0" /></td>
				</tr>
				<tr class="special">
					<td class="fieldTitle">要求工作天数</td>
					<td class="fieldContent"><input id="SubWorkDay" name="SubWorkDay"
						class="mini-textbox" style="width: 100%;" required="true"
						vtype="int" value="30" /></td>
					<td class="fieldTitle">返费次数</td>
					<td class="fieldContent"><input id="SubCount" name="SubCount"
						class="mini-textbox" style="width: 100%;" required="true"
						vtype="int" onvaluechanged="changeAmount" value="1" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">返费总次数</td>
					<td class="fieldContent"><input id="LimitCount" name="LimitCount"
						class="mini-textbox" style="width: 100%;" required="true"
						vtype="int" onvaluechanged="changeAmount" value="1" enabled="false" /></td>
					<td class="fieldTitle">返费总金额</td>
					<td class="fieldContent"><input id="TotalAmount"
						name="TotalAmount" class="mini-textbox" style="width: 100%;"
						required="false" enabled="false" vtype="float" value="0.0"/></td>
				</tr>
				<tr>
					<td class="fieldTitle">配置说明</td>
					<td class="fieldContent" colspan="3"><textarea id="Note"
							name="Note" style="width: 100%; height: 200px;" required="false"
							class="mini-textarea" emptyText="无"></textarea></td>
				</tr>
			</table>
		</div>
	</form>

	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		
		var rootPath = parent.getRootPath();
		var userName = parent.getUserName();
		var action = parent.getAction();
		var orgNo = parent.getOrgNo();
		var id = parent.getId();
		var nature = parent.parent.nature;
		var dataOri = null;
		
		var RewardType = mini.get("RewardType");
		var Amount1 = mini.get("Amount1");
		var Amount2 = mini.get("Amount2");
		var Amount3 = mini.get("Amount3");
		var Amount4 = mini.get("Amount4");
		var SubAmount1 = mini.get("SubAmount1");
		var SubAmount2 = mini.get("SubAmount2");
		var SubAmount3 = mini.get("SubAmount3");
		var SubAmount4 = mini.get("SubAmount4");
		var TotalAmount = mini.get("TotalAmount");
		var LimitCount = mini.get("LimitCount");
		var LimitCount1 = mini.get("LimitCount1");
		var SubCount = mini.get("SubCount");
		var WorkDay = mini.get("WorkDay");
		var SubWorkDay = mini.get("SubWorkDay");
		

		if (parent.hideAtt) {
			parent.hideAtt();
		
		}

		function changeType(e) {
			var value = e.value;
			if(value){
				var note = typeData[value].note;
				$('#explain').html(note);
				if(value == 3){
					$('.special').hide();
					LimitCount1.setValue(1);
					LimitCount1.disable();
					LimitCount.setValue(1);
					LimitCount.disable();
					WorkDay.enable();
					SubCount.disable();
				}else if(value == 4){
					$('.special').hide();
					WorkDay.setValue(0);
					WorkDay.disable();
					LimitCount1.enable();
					SubCount.disable();
				}else if(value == 5){
					$('.special').show();
					LimitCount1.enable();
					WorkDay.enable();
					SubCount.enable();
				}else{
					$('.special').hide();
					LimitCount1.enable();
					WorkDay.enable();
					SubCount.disable();
				}
				changeAmount();
			}
		}
		function changeAmount(){
			var type = RewardType.getValue();
			var total = 0.0;
			var value1 = Amount1.getValue();
			if(!value1){
				value1 = 0.0;
			}else{
				value1 = parseFloat(value1);
			}
			var value2 = Amount2.getValue();
			if(!value2){
				value2 = 0.0;
			}else{
				value2 = parseFloat(value2);
			}
			var value3 = Amount3.getValue();
			if(!value3){
				value3 = 0.0;
			}else{
				value3 = parseFloat(value3);
			}
			var value4 = Amount4.getValue();
			if(!value4){
				value4 = 0.0;
			}else{
				value4 = parseFloat(value4);
			}
			var sub_value1 = SubAmount1.getValue();
			if(!sub_value1){
				sub_value1 = 0.0;
			}else{
				sub_value1 = parseFloat(sub_value1);
			}
			var sub_value2 = SubAmount2.getValue();
			if(!sub_value2){
				sub_value2 = 0.0;
			}else{
				sub_value2 = parseFloat(sub_value2);
			}
			var sub_value3 = SubAmount3.getValue();
			if(!sub_value3){
				sub_value3 = 0.0;
			}else{
				sub_value3 = parseFloat(sub_value3);
			}
			var sub_value4 = SubAmount4.getValue();
			if(!sub_value4){
				sub_value4 = 0.0;
			}else{
				sub_value4 = parseFloat(sub_value4);
			}
			var count = LimitCount1.getValue();
			if(!count){
				count = 1;
			}else{
				count = parseInt(count);
			}
			var subCount = SubCount.getValue();
			if(!subCount){
				subCount = 0;
			}else{
				subCount = parseInt(subCount);
			}
			LimitCount.setValue(count+subCount);
			
			if(type == 1){//持续返费
				total = count*(value1+value2+value3+value4);
			}else if(type == 2){//叠加返费
				total = count*(count+1)*(value1+value2+value3+value4)/2;
			}else if(type == 3){//一次性返费
				total = value1+value2+value3+value4;
			}else if(type == 4){//按工作日返费
				total = count*(value1+value2+value3+value4);
			}else if(type == 5){//分阶段返费
				total = count*(value1+value2+value3+value4) + subCount*(sub_value1+sub_value2+sub_value3+sub_value4);
			}
			TotalAmount.setValue(total);
		}

		var form = new mini.Form("dataForm");

		SetFormData();

		function SetFormData() {
			if (action == "new") {
				var o = new Object();
				o.Nature = nature;
				o.OrgNo = orgNo;
				o.Amount1 = 0.0;
				o.Amount2 = 0.0;
				o.Amount3 = 0.0;
				o.Amount4 = 0.0;
				o.SubAmount1 = 0.0;
				o.SubAmount2 = 0.0;
				o.SubAmount3 = 0.0;
				o.SubAmount4 = 0.0;
				o.TotalAmount = 0.0;
				o.LimitCount1 = 1;
				o.LimitCount = 1;
				o.SubCount = 0;
				o.RewardType = 5;
				var note = typeData[1].note;
				$('#explain').html(note);
				o.WorkDay = 30;
				o.SubWorkDay = 30;
				form.setData(o);
				dataOri = o;
				return;
			}
			var messageid = mini.loading("获取中...", "Loading");
			var urlBase = '<c:url value="/config/reward/form/"></c:url>' + id;
			$.ajax({
				url : urlBase,
				type : "get",
				dataType : 'json',
				success : function(text) {
					if (!text) {
						return;
					}
					var o = mini.decode(text);
					var note = typeData[o.RewardType].note;
					$('#explain').html(note);
					form.setData(o);
					dataOri = o;
					parent.labelModel(form);
				},
				complete : function(XMLHttpRequest, textStatus) {
					mini.hideMessageBox(messageid);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {

				}
			});
		}
		function packData() {
			return form;
		}
		function parentChanged() {
			var value = ParentName.getValue();
			var object = value.split('serverSplit');
			ParentNo.setValue(object[0]);
		}
	</script>
</body>
</html>